package com.cty.tree;
/*
* 二叉树类
*
* */
public class BinaryTree {
    private HeroNode root;
    //初始化传入一个头节点
    public BinaryTree(HeroNode root) {
        this.root = root;
    }
    //前序遍历
    public void preOrder() {
        if (root == null) {
            System.out.println("二叉树为空~~");
            return;
        } else {
            root.proOrder();
        }
    }

    //中序遍历
    public void midOrder() {
        if (root == null) {
            System.out.println("二叉树为空");
            return;
        } else {
            root.midOrder();
        }
    }

    //后序遍历
    public void postOrder() {
        if (root == null) {
            System.out.println("空二叉树~~");
            return;
        } else {
            root.postOrder();
        }
    }

    //前序查找
    public HeroNode preOrderSearch(int no) {
        HeroNode resNode = null;
        resNode = root.preOrderSearch(no);
        if (resNode != null) {
            return resNode;
        } else {
            return null;
        }
    }

    //中序查找
    public HeroNode midOrderSearch(int no) {
        HeroNode resNode = null;
        resNode = root.midOrderSearch(no);
        if (resNode != null) {
            return resNode;
        } else {
            return null;
        }
    }

    //后序查找
    public HeroNode postOrderSearch(int no) {
        HeroNode resNode = null;
        resNode = root.postOrderSearch(no);
        if (resNode != null) {
            return resNode;
        } else {
            return null;
        }
    }

    //删除节点
    public void delNode(int no) {
        if (root == null) {
            System.out.println("二叉树为空~~");
            return;
        }
        if (root.id == no) {
            root = null;
            return;
        } else {
            root.delNode(no);
        }
    }
}
